Week 5 of 16

Functions, Modules & Virtual Environments

Learn why functions exist, how modules split code across files, and how virtual environments keep your projects clean.

Day 21 60 minutes Watch

Day 21 of 80

What You'll Accomplish Today

Before the Videos: Set Up a Virtual Environment

Do this first — it takes 2 minutes and you'll understand it better after watching the third video. Open your terminal in the prompt-vault/ folder and run:

Terminal — prompt-vault/
$ python -m venv venv
# Creates a venv/ folder — your isolated Python sandbox

$ venv\Scripts\activate
(venv) $
# You're now inside the environment. Notice (venv) in the prompt.

(venv) $ pip install anthropic python-dotenv
Successfully installed anthropic-... python-dotenv-...
What Just Happened

You created a private Python sandbox. The anthropic and python-dotenv packages are now installed only inside this project — not globally on your machine. When Corey explains why this matters, you'll have already experienced it firsthand.

Today's Videos

All three are from Corey Schafer's Python Beginner series — some of the clearest Python teaching on the internet. Watch them in order.

# Video Length Focus
1 Functions ~20 min Parameters, return values, scope
2 Import Modules and Exploring the Standard Library ~25 min Splitting code across files, the standard library
3 Virtual Environments Tutorial ~15 min Keeping project libraries separate
Why Functions Matter Now — You've Already Used Them

Back in Week 3, you wrote load_prompts() and save_prompts(). You used them without fully understanding why they were written as functions. Today Corey explains the WHY behind every function you've already used:

When you hear these explained clearly, you'll feel that satisfying click of "oh — that's what I've been doing."

Key Concepts to Watch For

Parameters vs. Arguments

Parameters are the variable names defined in the function signature. Arguments are the values you pass when calling it. Corey explains this clearly — it's a distinction worth locking in now.

Return Values

A function can give something back to the code that called it. Without return, the function does its work and disappears. With return, it hands you a value you can store in a variable or pass somewhere else. Your load_prompts() uses this — it returns the list of prompts.

Scope

Variables created inside a function only exist inside that function. This is a feature, not a limitation — it means your functions can't accidentally break each other's data. Corey demonstrates this with examples that make the rule stick.

Modules and Imports

When you write import json, you're using Python's module system. Corey shows you that your own files work exactly the same way — you can split your code into multiple .py files and import functions between them. This is what Day 23's build project uses.

Virtual Environments

Each Python project can have its own private set of installed packages. A virtual environment is that private sandbox. Without it, installing a new package for one project can break a different project that needs an older version. By the end of Week 5, every project you create will start with python -m venv venv.

How to Watch These Videos

Don't just let them run in the background. Get the most out of 60 minutes:

Connection to Your Project

As you watch, keep your Week 3 and Week 4 code open in another window. Notice:

End of Day Checklist

Tomorrow — Day 22: Read + Jupyter Experiments

Tomorrow you put today's theory into practice. You'll read Cursor's Python guide (15 minutes), then run four Jupyter notebook cells exploring default parameters, multiple return values, and how to organize imports. All the examples use your Prompt Vault data — video shots, platforms, filenames.